package hot100;

public class lengthOfLongestSubstring2 {
    public int lengthOfLongestSubstring(String s) {
        int[] hash = new int[127];
        int l = 0;
        int r = 0;
        int n = s.length();
        int max =0;
        while(r < n) {
            char a = s.charAt(r);
            hash[a]++;
            while(hash[a] > 1) {
                hash[s.charAt(l)]--;
                l++;
            }
            r++;
            max = Math.max(r-l,max);
        }
        return max;
    }
}
